<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>家庭成员添加</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/index.css">
        <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/index.js"></script>
        <script type="text/javascript" src="js/jquery.min.js"></script>
         <script type="text/javascript" charset="utf-8" src="js/jquery-form.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->

    </head>
    <body>
        
        
        <div class="x-body">
    		<form class="layui-form layui-form-pane" action="${pageContext.request.contextPath}/FamilyServlet" method="post" id="add-form" enctype="multipart/form-data">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                    <input type="hidden" name="op" value="add">
                    

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>姓名
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="familyName" autocomplete="off" placeholder=" "
                                   class="layui-input" value=""  required>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>身份证号码
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="familyCard" autocomplete="off" placeholder=" "
                                   class="layui-input" value=""  required>
                        </div>
                    </div>
                    
                    
                    
                   
                    
                    
                    
                    <div class="layui-form-item">
                        <label  class="layui-form-label">
                            <span class="x-red" >*</span>相片
                        </label>
                        <div class="layui-input-block">
                           <div class="site-demo-upbar">
                                <div class=" layui-upload-button" style="border:#FFFFFF ;">
                                    <button type="button" class="layui-btn" id="test1">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                    <input class="layui-upload" type="file"  id="previewImg" name="familyImage"  required>
                                </div>

                            </div>
                        </div>
                       </div> 
                       
                       <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>相片预览
                        </label>
                        <div class="layui-input-block">
                            <img src="" id="image-show" name="pimages" style="width: 400px;height: 200px;"/>
                        </div>
                    </div>
                       
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>门牌号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="roomNo" autocomplete="off" placeholder=" "
                                   class="layui-input" value="" required>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>类型（与户主关系）
                        </label>
                        <div class="layui-input-block">
                            <select name="familyTypeId" id="typeId">

                                <option value="0">---请选择类型---</option>
                                
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>手机号码
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="familyPhone" autocomplete="off" placeholder=" "
                                   class="layui-input" value=""  required>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <button class="layui-btn" type="submit" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>

                    <div style="height:100px;"></div>
                </div>



            </div>

        </div>
    </form>
</div>
</body>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>
 
<script type="text/javascript" src="js/jquery.js"></script>
<script src="js/jquery-form.js"></script>
<script>
//获取家庭成员类型列表
$.getJSON("${pageContext.request.contextPath}/FamilyTypeServlet",{op:"getList"},function(result,status,xhr){
	let content = "";
	$.each(result.data,function(i,obj){
		content+=
			
			"<option value=\""+obj.familyTypeNo+"\">"+obj.familyTypeName+"</option>";
		 
	});
	//填充到下拉框
	$("#typeId").html(content);
});

//对指定的表单绑定提交事件
$("#add-form").submit(function(){
	$(this).ajaxSubmit(function(result){
		//使用layui弹出提示信息
		layui.use('layer',function(){
			layer.msg(result.message,{icon:1,time:3000});
			if(result.status!=0){
				window.setTimeout(function(){
					//调用首页的查询
					window.parent.family_search();
					//关闭子窗口
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				},3000);
			}
		});
		
		
	});
	//限制表单的默认提交
	return false;
});

//图片预览 为文件上传绑定change事件
$("#previewImg").change(function(event){
	//根据这个input获取文件的 HTML5 js 对象
    let files = event.target.files, file;
    if (files && files.length > 0) {
        // 获取目前上传的图片
        file = files[0];
        // 控制打印file对象
        console.log(file);
        // 限制图片上传大小
        if (file.size > 102400) {
            alert('图片大小不能超过 100kb!');
            $("#input-image").val("");
            return false;
        }
        // 通过这个 file 对象生成一个可用的图像 URL
        // 获取 window 的 URL 工具
        let URL = window.URL || window.webkitURL;
        // 通过 file 生成目标 url
        let imgURL = URL.createObjectURL(file);
        $("#image-show").attr("src", imgURL);
    }
	
});
</script>   
<script>
layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //自定义验证规则
                form.verify({
                    nikename: function(value) {
                        if (value.length < 5) {
                            return '昵称至少得5个字符啊';
                        }
                    },
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    repass: function(value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    }
                });

                //监听提交
                form.on('submit(addd)',
                function(data) {
                    console.log(data);
                    //发异步，把数据提交给php
                    layer.alert("增加成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();

                        // 可以对父窗口进行刷新 
                        xadmin.father_reload();
                    });
                    return false;
                });

            });
</script>
<script>
/*var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();*/
</script>
</html>
